package com.kzc.controller.stock;

import com.kzc.base.ResponseWrapper;
import com.kzc.bean.CarBean;
import com.kzc.contst.Constants;
import com.kzc.mapper.stock.StockMapper;
import com.kzc.util.ResponseDataUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 车辆库存
 */
@RestController
@RequestMapping("/car")
public class StockController {

     @Autowired(required = false)
     StockMapper stockMapper;

     @RequestMapping(value = "/findAllCar" , method = RequestMethod.GET)
     public ResponseWrapper<CarBean> findAllCar(HttpServletRequest request){

         String pageStr = request.getParameter("page");
         String pageNumStr = request.getParameter("pageNum");
         int page = Constants.DATA_PAGE;
         int pageNum = Constants.DATA_PAGE_SIZE ;

         if(pageStr!=null && !pageStr.isEmpty()){
             page = Integer.parseInt(pageStr);
         }

         if(pageNumStr!=null && !pageNumStr.isEmpty()){
             pageNum = Integer.parseInt(pageNumStr);
         }

         if(page != 0){
             page-=1;
         }

         List<CarBean> carBeanList = stockMapper.findAllCar(page*pageNum,pageNum);

        return  ResponseDataUtils.responseSuccess(Constants.RESPONSE_SUCCESS_STATUS,
                "",null,carBeanList);
     }


     @PostMapping(value = "/findByStockId")
     public int findByStockId(){
         int id  = stockMapper.findByStockId();
         return id;
     }


     @PostMapping(value = "/insertDistCar" ,consumes = "application/json")
     @ResponseBody
     public int insertDistCar(@RequestBody CarBean carBean){

         return stockMapper.distributionCar(carBean);

     }

}
